#include <string.h>
#include <iostream>
using std::cout;
using std::endl;
class Computer
{
public:
    static Computer *create(int price,char * brand){
        return new Computer(price,brand);
    }
    void *operator new(size_t size)
    {
        void *result = malloc(size);
        return result;
    }
    void operator delete(void *p)
    {
        free(p);
    }
    Computer(const Computer&rhs)
    :_price(rhs._price)
    ,_brand(new char[strlen(rhs._brand)+1])
    {
        strcpy(_brand,rhs._brand);
    }
    //拷贝赋值函数
    Computer & operator=(const Computer&rhs)
    {
        if(this == &rhs){
            return *this;
        }
        delete [] _brand;
        _price = rhs._price;
        _brand = new char[strlen(rhs._brand)+1];
        strcpy(_brand,rhs._brand);
        return *this;
    }
    void destory()
    {
        delete this;
    }

private:
    Computer(int price, const char *brand)
        : _price(price), _brand(new char[strlen(brand) + 1]())
    {
        strcpy(_brand, brand);
    }
    ~Computer()
    {
        if (_brand != NULL)
        {
            delete[] _brand;
        }
    }
    int _price;
    char *_brand;
};

void test()
{
    Computer * pc1 = Computer::create(5000,"HUAWEI");
    Computer *pc2 = new Computer(*pc1);
    Computer* pc3 = Computer::create(6000, "Lenovo");
    *pc3 = *pc1; 
}
int main()
{
    test();
    return 0;
}
